<?php
class Category extends AppModel {
	var $name = 'Category';
	var $validate = array(
		'name' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $hasMany = array(
		'Link' => array(
			'className' => 'Link',
			'foreignKey' => 'category_id',
			'dependent' => false,
		),
		'Children'=>array(
			'className' => 'Category',
			'foreignKey' => 'parent',
			'dependent' => true,
		)
	);
	
	var $belongsTo=array(
		'Parent' => array(
			'className' => 'Category',
			'foreignKey' => 'parent',
			'dependent' => false
		)
	);
	
	function getCats(){
		return $this->find('all',array(
			'fields'=>array('id','name'),
			'conditions'=>array('parent'=>0),
			'contain'=>array('Children'=>array('id','name')),
			'cacheKey'=>'cats'
		));
	}

}
?>